<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Home\Controller;

use Think\Controller;

/**
 * 林州市悟能科技提供技术支持
 * 400-037203
 * @author Mr_Lee :672288511;
 */
class PayController extends Controller
{
    public function _initialize()
    {
        if (empty($_SESSION['username'])) {


            $this->error('页面加载中。。。', U('Login/Login'), 1);

        }
        $table1="pay";
        $this->assign('table',$table1);
    }

    public function paycount()
    {
        if (IS_POST) {
            if (I('post.wtime')) {
                $wtime = strtotime(I('post.wtime'));
            } else {
                $wtime = 0;
            }
            if (I('post.ntime')) {
                $ntime = strtotime(I('post.ntime'));
            } else {

                $ntime = time();
            }

            $this->assign('wtime', I('post.wtime'));
            $this->assign('ntime', I('post.ntime'));
            $where1 = array(
                'addtime' => array('between', '' . $wtime . ',' . $ntime . ''),
                'xingming' => array('like', '%' . I('post.sj').'%'),
            );
        }else {
            $where1 = array(
                'addtime' => array('like', '%'),

            );
        }
        // dump($where1);
        $where2 = array(
            // 'pay_statu' => 1,
            '_complex' => $where1, // 复合查询

        );
        $where3 = array(
            'status' => 6,
            // 'order_statu'=>1,
            '_complex' => $where1, // 复合查询

        );
        $where4 = array(
            'status' => 6,
            // 'order_statu'=>1,
            '_complex' => $where1, // 复合查询

        );
        // dump($where2);
        $order = M('xllog');
        $bwcount = $order->where($where2)->count('id');
        $bwcount2 = $order->where($where2)->sum('price*num');
        $bwcount3 = $order->where($where3)->count('id');
        $bwcount4 = $order->where($where4)->sum('price*num');
        $sj=M('siji')->select();
        $this->assign('sj',$sj);

        $this->assign('bwcount', $bwcount);
        $this->assign('bwcount2', $bwcount2);
        $this->assign('bwcount3', $bwcount3);
        $this->assign('bwcount4', $bwcount4);
        $this->display();
    }
//    public function czadmin(){
//        $czlog=M('czlog');
//
//
//        $log=$czlog->select();
//        $this->assign('log',$log);
//
//        $this->display();
//    }
    public function Paysetting()
    {
        $pay = M('User');
        if (IS_AJAX) {
            $pay->create();
            $up = $pay->save();
            if ($up) {

                $data = 0;
            } else {

                $data = 1;
            }
            echo $data;

        } else {
            $map['id'] = 1;

            $config = new ConfigController();
            $configs = $config->getConfig();
            $maintain = $config->getMaintain();
            $payinfo = $config->getPayinfo();
            $fare = $config->getFare();
            $buslicense = $config->getBuslicense();
            $seragency = $config->getSeragency();
            $maintain['CompanyId'] = C('CompanyId');

            $this->assign('maintain',$maintain);
            $this->assign('payinfo',$payinfo);
            $this->assign('fare',$fare);
            $this->assign('buslicense',$buslicense);
            $this->assign('seragency',$seragency);
            $this->assign('config',$configs);
            $us = $pay->where($map)->find();
            $this->assign('us', $us);
            $this->display('sysconfig');
        }
    }
    public function czadmin()
    {
        if (IS_POST) {

            if (I('post.wtime')) {
                $wtime = strtotime(I('post.wtime'));
            } else {
                $wtime = 0;
            }
            if (I('post.ntime')) {
                $ntime = strtotime(I('post.ntime'))+86399;
            } else {
                $ntime = time();
            }

            $this->assign('wtime', I('post.wtime'));
            $this->assign('ntime', I('post.ntime'));
            $where1 = array(
                'addtime' => array('between', '' . $wtime . ',' . $ntime . ''),
            );

        } else {
            $where1 = array(
                'addtime' => array('like', '%'),

            );


        }
        //全部订单
        $where = array(

            '_complex' => $where1, // 复合查询

        );

        $czlog = M('czlog');
        $cz = $czlog->where($where)->select();
        //总笔数
        $zcount = $czlog->where($where)->count();
        //支付金额
        $psum = $czlog->where($where)->sum('price');
        //赠送金额
        $fsum = $czlog->where($where)->sum('free');
        $this->assign('zcount', $zcount);
        $this->assign('psum', $psum);
        $this->assign('fsum', $fsum);
        $this->assign('zsum', $psum + $fsum);
        $this->assign('cz', $cz);
        $this->display();

    }

    //put your code here
}
